package es.mllacer.qqsm.util;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class RemoteScoresItemizedOverlay extends ItemizedOverlay<OverlayItem> {

	private List<OverlayItem> list;

	private Context context;

	public RemoteScoresItemizedOverlay(Context context, Drawable marker) {
		super(boundCenter(marker));
		list = new ArrayList<OverlayItem>();
		this.context = context;
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return list.get(i);
	}

	@Override
	public int size() {
		return list.size();
	}

	public void addOverlay(OverlayItem item) {
		list.add(item);
		populate();
	}

	@Override
	protected boolean onTap(int i) {
		OverlayItem item = list.get(i);
		AlertDialog.Builder dialog = new AlertDialog.Builder(context);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}

}
